package cn.community.system.web.controller;

import cn.community.system.query.QueryObject;
import cn.community.system.service.IPermissionService;
import cn.community.system.util.JsonResult;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/permission")
public class PermissionController {
    
    @Autowired
    private IPermissionService permissionService;

    @RequestMapping("/list")
    @RequiresPermissions(value = {"permission/list","权限信息列表"},logical = Logical.OR)
    public String list(Model model, @ModelAttribute("qo") QueryObject qo){
        model.addAttribute("page", permissionService.query(qo));
        return "permission/list";
    }

    @RequestMapping("/reload")
    @ResponseBody
    @RequiresPermissions(value = {"permission/reload","权限信息加载"},logical = Logical.OR)
    public JsonResult reload(){
        try {
            permissionService.reload();
            return JsonResult.success("加载成功");
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.error(JsonResult.CODE_ERROR_LOADINGFAILED,JsonResult.MSG_LOADINGFAILED,"加载失败");
        }
    }

}
